package org.trinity.netdisk.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@RestController
public class TestController {

    @RequestMapping("/test")
    private void test(HttpServletRequest req,HttpServletResponse response) throws IOException {
        String path = "/Trinity/Backup/install_81ent.wim";
        File file =  new File(path);
        OutputStream os = response.getOutputStream();
        InputStream is = new FileInputStream(path);
        response.setHeader("Content-disposition", "attachment;filename=" + file.getName());
        byte[] buff = new byte[10240];
        int len;
        while ( (len = is.read(buff)) != -1 ){
            os.write(buff,0,len);
        }
        os.flush();
        os.close();
    }

    @Controller
    class test{
        @RequestMapping("/s/{file}")
        private String s(){
            return "/shareFile.html";
        }
    }
}
